package cn.ztuo.bitrade.controller;

import cn.ztuo.bitrade.entity.Coin;
import cn.ztuo.bitrade.entity.ContractWallet;
import cn.ztuo.bitrade.entity.transform.AuthMember;
import cn.ztuo.bitrade.service.CoinService;
import cn.ztuo.bitrade.service.ContractWalletService;
import cn.ztuo.bitrade.util.MessageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import java.util.List;

import static cn.ztuo.bitrade.constant.SysConstant.SESSION_MEMBER;

@RestController
@RequestMapping("/contract")
@Slf4j
public class ContractWalletController extends BaseController {

    @Autowired
    private ContractWalletService contractWalletService;

    @Autowired
    private CoinService coinService;

    @PostMapping("/get-wallet")
    public MessageResult findByWallet(@SessionAttribute(SESSION_MEMBER) AuthMember member) {
        log.info("================查询用户合约账户==============="+ member.getId());
        List<ContractWallet> wallets = contractWalletService.findAllByMemberId(member.getId());
        wallets.forEach(wallet -> {
            Coin coin = (Coin) coinService.findById(wallet.getCoinId());

            wallet.setCoinLogo(coin.getLogo());
        });
        return success(wallets);
    }


}
